package com.xinggq.user.service.dto.role;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.xinggq.user.service.entity.SysRoleEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;

/**
 * 角色响应VO
 *
 * @author system
 * @since 2025-01-10
 */
@Data
@Accessors(chain = true)
@Schema(description = "角色响应VO")
public class RoleVO {

    @Schema(description = "角色ID")
    private Long id;

    @Schema(description = "租户ID")
    private Long tenantId;

    @Schema(description = "角色名称")
    private String roleName;

    @Schema(description = "角色编码")
    private String roleCode;

    @Schema(description = "角色描述")
    private String description;

    @Schema(description = "是否系统角色：0-否，1-是")
    private Integer isSystem;

    @Schema(description = "状态：1-正常，0-禁用，-1-删除")
    private Integer status;

    @Schema(description = "排序")
    private Integer sortOrder;

    @Schema(description = "创建人ID")
    private Long createdBy;

    @Schema(description = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createdAt;

    @Schema(description = "更新人ID")
    private Long updatedBy;

    @Schema(description = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime updatedAt;

    /**
     * 从实体转换为VO
     *
     * @param entity 角色实体
     * @return 角色VO
     */
    public static RoleVO fromEntity(SysRoleEntity entity) {
        if (entity == null) {
            return null;
        }
        return new RoleVO()
                .setId(entity.getId())
                .setTenantId(entity.getTenantId())
                .setRoleName(entity.getRoleName())
                .setRoleCode(entity.getRoleCode())
                .setDescription(entity.getDescription())
                .setIsSystem(entity.getIsSystem())
                .setStatus(entity.getStatus())
                .setSortOrder(entity.getSortOrder())
                .setCreatedBy(entity.getCreatedBy())
                .setCreatedAt(entity.getCreatedAt())
                .setUpdatedBy(entity.getUpdatedBy())
                .setUpdatedAt(entity.getUpdatedAt());
    }
}